<?php

class Zend_View_Helper_PriceSpecial
{	
	public $currency = array(
		'cs' => 'CZK',
		'en' => 'EUR'
	);
	
	public function PriceSpecial( $item, $rank, $locale, $cur = false ) {
		$currencyValue = false;
		if( $cur ) {
			$Currency = new Currency();
			$items = $Currency->getListService()->toArray();
			$crroz = isSet( $this->currency[$locale] ) ? ' ' . $this->currency[$locale] : ' PLN';
			
			if( $locale != 'pl' ) {
				foreach( $items as $value ) {
					if( $value['name'] == $this->currency[$locale] ) {
						$currencyValue = $value['value'];
					}
				}
			}

		} else {
			$crroz = '';
		}

		if( !$currencyValue ) {
			$brutto = 0;
			if( $item['Vat']['rate'] > 0 ) {
				$brutto = ( $item['price' . $rank] * $item['Vat']['rate'] ) / 100;
			}
			$brutto = $brutto + $item['price' . $rank];
			
			return $brutto . $crroz;
		} else {
			$brutto = 0;
			$am = $item['price' . $rank];

			if( $item['Vat']['rate'] ) {
				$brutto = ( $am * $item['Vat']['rate'] ) / 100;
			}
			$brutto = $brutto + $am;
			
			$am = $brutto / $currencyValue;
			
			return number_format( $am, 2, '.', ' ') . $crroz;
		}
	}
}